package com.longqinuo.mycarservice.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;


import com.longqinuo.mycarservice.MainActivity;
import com.longqinuo.mycarservice.R;
import com.longqinuo.mycarservice.utils.SPUtils;


public class LaunchActivity extends AppCompatActivity {

    private boolean flag = true;
    private Intent mIntent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        isFirst();
    }

    private  void initData() {
        mIntent = new Intent();

    }

    public void isFirst() {
        flag = (boolean) SPUtils.getSp(this,"first",true);
        if (flag) {
            mIntent.setClass(this,GuideActivity.class);
            SPUtils.setSP(this,"first",false);
            startActivity(mIntent);
            finish();
        } else {
            setContentView(R.layout.activity_launch);
            ImageView launchImage = (ImageView) findViewById(R.id.iv_launch_image);
            Animation animation = AnimationUtils.loadAnimation(this,R.anim.launch_anim);
            launchImage.startAnimation(animation);
            animation.start();
            new Thread(){
                @Override
                public void run() {
                    super.run();
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    mIntent.setClass(LaunchActivity.this,MainActivity.class);
                    startActivity(mIntent);
                    finish();
                }
            }.start();

        }
    }

}
